package com.example.demoamqp.send;

import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 延迟队列
 *
 * @className: DelayQueueSender
 * @projectName: demo-one
 * @auth: rosszhang
 * @date: 2023/12/28 17:36
 */
@Slf4j
@Component
public class DelayQueueSender {
    private AmqpTemplate rabbitAmqpTemplate;

    @Autowired
    public void setRabbitAmqpTemplate(AmqpTemplate rabbitAmqpTemplate) {
        this.rabbitAmqpTemplate = rabbitAmqpTemplate;
    }

    public void sendMsg(String msg) {
        log.info("当前时间：{}，发送给两个TTL队列：{}", DateUtil.date(), msg);

        //生产者使用普通交换机X 通过 信道XA 向普通队列QA发送消息
        rabbitAmqpTemplate.convertAndSend("X", "XA", "消息来自ttl为10s的队列：" + msg);
        //生产者使用普通交换机X 通过 信道XB 向普通队列QB发送消息
        rabbitAmqpTemplate.convertAndSend("X", "XB", "消息来自ttl为40s的队列：" + msg);

    }
}
